import { h, ref } from 'vue';
import { CaretDownFilled } from '@ant-design/icons-vue';

// 自定义过滤图标的方法
// 定义 filterIcon 方法
const filterIcon = (filtered, onFilter, column) => {
  return h(CaretDownFilled, {
    style: {
      fontSize:'15px'
    },
    onClick: () => onFilter(null, column),
  });
}

let obj = {
  formType: 'select',
  customFilterDropdown: true,
  filterIcon,
  onFilter: (value, record) => filterFn(value, record),
}

const filterFn = (value, record) => {
  return record.name.toString().toLowerCase().includes(value.toLowerCase())
}

// 获取当前状态
const current = ref()
export const ifShowFun = ({ status })  =>{
  current.value = status
}

// options集合
let optionsObject = {
  sex : [
    {
      value: '0',
      label: '男'
    },
    {
      value: '1',
      label: '女'
    }
  ],
  qualificationType: [
    {
      value: '1',
      label: '本科'
    },
    {
      value: '2',
      label: '硕士'
    },
    {
      value: '3',
      label: '博士'
    },
  ],
  region:[
    {
      value: '1',
      label: '一部'
    },
    {
      value: '0',
      label: '二部'
    },
    {
      value: '2',
      label: '三部'
    },
    {
      value: '3',
      label: '四部'
    },
  ],
}

//table
export const columns: any[] = [
  {
    title: '姓名',
    dataIndex: 'userName',
    key: 'userName',
    formType: 'input',
    customFilterDropdown: true,
    filterIcon,
    fixed: 'left',
    width:100
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    key: 'phone',
    formType: 'input',
    customFilterDropdown: true,
    filterIcon,
    fixed: 'left',
    width:120
  },
  {
    title: '操作',
    dataIndex: 'processStatus',
    formType: 'select',
    key: 'processStatus',
    fixed: 'left',
    ifShow: () => {
      return current.value < 2
    },
    width:110
  },
  {
    title: '状态',
    dataIndex: 'processStatusName',
    key: 'processStatusName',
    ...obj,
    formType: 'select',
    otherFormType: 'search',
    params: 'processStatus',
    width:150
  },
  {
    title: '录取分校',
    dataIndex: 'entryLocation',
    key: 'entryLocation',
    ifShow: () => {
      return current.value == 3
    },
    ...obj,
    otherFormType: 'search',
    params: 'area',
    width:180
  },
  {
    title: '录取科目',
    dataIndex: 'entrySubject',
    key: 'entrySubject',
    ifShow: () => {
      return current.value == 3
    },
    ...obj,
    otherFormType: 'search',
    params: 'subject',
    width:140
  },
  {
    title: '录取年级',
    dataIndex: 'entryGrade',
    key: 'entryGrade',
    ifShow: () => {
      return current.value == 3
    },
    ...obj,
    otherFormType: 'search',
    params: 'grade',
    width:140
  },
  {
    title: '预计到岗时间',
    dataIndex: 'onDutyTime',
    key: 'onDutyTime',
    ifShow: () => {
      return current.value == 3
    },
    formType:'time',
    customFilterDropdown: true,
    filterIcon,
    width:160
  },
  {
    title: '小组',
    dataIndex: 'group',
    key: 'group',
    ifShow: () => {
      return current.value > 0 // 根据业务控制是否显示
    },
    ...obj,
    otherFormType: 'search',
    customRender: ({ text }) => {
      return text || '--';
    },
    editx: true,
    width:100
  },
  {
    title: '选题',
    dataIndex: 'questions',
    key: 'questions',
    ifShow: () => {
      return current.value > 0
    },
    ...obj,
    otherFormType: 'search',
    customRender: ({ text }) => {
      return text || '--'
    },
    editx: true,
    width:140
  },
  {
    title: '考核官',
    width: 200,
    dataIndex: 'assessUserName',
    key: 'assessUserName',
    ifShow: () => {
      return current.value > 0
    },
    ...obj,
    otherFormType: 'search',
    params: 'assessUserId',
    editx: true,
  },
  {
    title: '性别',
    dataIndex: 'sex',
    key: 'sex',
    ...obj,
    options: optionsObject.sex,
    width:80
  },
  {
    title: '学历',
    dataIndex: 'qualificationType',
    key: 'qualificationType',
    ...obj,
    width:80
  },
  {
    title: '毕业时间',
    dataIndex: 'graduateTime',
    formType:'time',
    key: 'graduateTime',
    sorter: true,
    width:120
  },
  {
    title: '学校',
    dataIndex: 'schoolName',
    key: 'schoolName',
    formType: 'input',
    customFilterDropdown: true,
    filterIcon,
    history:true,
    width:140
  },
  {
    title: '学院',
    dataIndex: 'schoolDepartment',
    key: 'schoolDepartment',
    formType: 'input',
    customFilterDropdown: true,
    onFilter: (value, record) => filterFn(value, record),
    onFilterDropdownOpenChange: (visible) => {
      if (visible) {}
    },
    filterIcon,
    width:140
  },
  {
    title: '所属大区',
    dataIndex: 'region',
    key: 'region',
    ...obj,
    params: 'regionName',
    width:140
  },
  {
    title: '维护HR',
    dataIndex: 'preserveUserName',
    key: 'preserveUserName',
    ...obj,
    otherFormType: 'search',
    params: 'preserveUserIds',
    width:120
  }
];

// 状态
export const statusList = [
  {
    name:'未开始',
    status: 'error',
    value: 0,
  },
  {
    name:'培训中',
    status: 'success',
    value: 1,
  },
  {
    name:'考核中',
    status: 'warning',
    value: 2,
  },
  {
    name:'已结束',
    status: 'default',
    value: 3,
  },
]

// 查找对应文案
export function textFind(value ,key){
  let item = optionsObject[key].find(item => item.value == value) || {}
  return item.label || '--'
}

// 数组数据展示
export function textShow(data){
  if(data?.length > 0){
    return data.join('、')
  }
  return ''
}

// 操作
export const operationObject = {
  'TRAINING_EMAIL_SENT': '发送邮件',
  'TRAINING_EMAIL_ACCEPTED': '重发邮件',
  'TRAINING_ARRIVAL_SCHEDULED': '确认到培',
  'TRAINING_IN_PROGRESS': '取消到培',
  'TRAINING_ARRIVAL_DECLINED': '确认到培', // 培训 放弃 置灰
}